﻿Imports System.Data.Common
Imports System.Data.SqlClient
Imports System.ComponentModel

Friend Class SqlConnectionProperties
    Inherits AdoDotNetConnectionProperties
    ' Methods
    Public Sub New()
        MyBase.New("System.Data.SqlClient")
        Me.LocalReset()
    End Sub

    Protected Overrides Sub Inspect(ByVal connection As DbConnection)
        If (connection.ServerVersion.StartsWith("07", StringComparison.Ordinal) OrElse connection.ServerVersion.StartsWith("08", StringComparison.Ordinal)) Then
            Throw New NotSupportedException(My.Resources.SqlConnectionProperties_UnsupportedSqlVersion)
            'SR.GetString("SqlConnectionProperties_UnsupportedSqlVersion"))
        End If
    End Sub

    Private Sub LocalReset()
        Me.Item("Integrated Security") = True
    End Sub

    Public Overrides Sub Reset()
        MyBase.Reset()
        Me.LocalReset()
    End Sub

    Public Overrides Sub Test()
        Dim str As String = TryCast(MyBase.ConnectionStringBuilder.Item("Data Source"), String)
        If ((str Is Nothing) OrElse (str.Length = 0)) Then
            Throw New InvalidOperationException(My.Resources.SqlConnectionProperties_MustSpecifyDataSource)
            'SR.GetString("SqlConnectionProperties_MustSpecifyDataSource"))
        End If
        Dim str2 As String = TryCast(MyBase.ConnectionStringBuilder.Item("Initial Catalog"), String)
        Try
            MyBase.Test()
        Catch exception As SqlException
            If (((exception.Number = &HFDC) AndAlso (Not str2 Is Nothing)) AndAlso (str2.Length > 0)) Then
                Throw New InvalidOperationException(My.Resources.SqlConnectionProperties_CannotTestNonExistentDatabase)
                'SR.GetString("SqlConnectionProperties_CannotTestNonExistentDatabase"))
            End If
            Throw
        End Try
    End Sub

    Protected Overrides Function ToTestString() As String
        Dim flag As Boolean = CBool(MyBase.ConnectionStringBuilder.Item("Pooling"))
        Dim flag2 As Boolean = Not MyBase.ConnectionStringBuilder.ShouldSerialize("Pooling")
        MyBase.ConnectionStringBuilder.Item("Pooling") = False
        Dim connectionString As String = MyBase.ConnectionStringBuilder.ConnectionString
        MyBase.ConnectionStringBuilder.Item("Pooling") = flag
        If flag2 Then
            MyBase.ConnectionStringBuilder.Remove("Pooling")
        End If
        Return connectionString
    End Function


    ' Properties
    Protected Overrides ReadOnly Property DefaultProperty As PropertyDescriptor
        Get
            Return Me.GetProperties(New Attribute(0 - 1) {}).Item("DataSource")
        End Get
    End Property

    Public Overrides ReadOnly Property IsComplete As Boolean
        Get
            If (Not TypeOf MyBase.ConnectionStringBuilder.Item("Data Source") Is String OrElse (TryCast(MyBase.ConnectionStringBuilder.Item("Data Source"), String).Length = 0)) Then
                Return False
            End If
            Return (CBool(MyBase.ConnectionStringBuilder.Item("Integrated Security")) OrElse (TypeOf MyBase.ConnectionStringBuilder.Item("User ID") Is String AndAlso (TryCast(MyBase.ConnectionStringBuilder.Item("User ID"), String).Length <> 0)))
        End Get
    End Property


    ' Fields
    Private Const SqlError_CannotOpenDatabase As Integer = &HFDC
End Class

